home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17113 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  25 lines

  1. Path: pluto.njcc.com!not-for-mail
  2. From: mike@pluto.njcc.com (Michael Hohenshilt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Calling the wrong constructor
  5. Date: 13 Apr 1996 18:53:59 GMT
  6. Organization: New Jersey Computer Connection, Lawrenceville, NJ
  7. Message-ID: <4kot87$796@earth.njcc.com>
  8. NNTP-Posting-Host: pluto.njcc.com
  9. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  10.  
  11.   This might seem like a basic question, but lets say you something set u 
  12. like the following:
  13.  
  14. class Parent { Parent() { allocsomething} ~Parent() { deletesomething }... };
  15. class Foo : Parent { Foo() { allocsomething } ~Foo() {deletesomething }... };
  16. class Contain { Parent *ptr; ... };
  17.  
  18. both parent, and foo allocate memory, and will free it up when being 
  19. destructed.  Contain just holds a pointer of type Parent, and its 
  20. constructor takes such a pointer as a parameter.
  21.   If I store a pointer of type Foo into contain.ptr and discard that 
  22. pointer.  Is there any way to have contain (via destructors) free up all 
  23. memory allocated by Foo and/or Parent?
  24.          Mike
  25.